package com.example.javatwo.service.cg.lch;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.javatwo.mapper.cg.lch.xjdMapper;
import com.example.javatwo.pojo.cg.lch.Inquiryxb;
import com.example.javatwo.pojo.cg.lch.Inquiryzb;
import com.example.javatwo.pojo.cg.lch.history;
import com.example.javatwo.pojo.cg.yt.DsDataSet1;

@Service
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public class xjdService {
@Autowired
private xjdMapper xjdmapper;
/**
 * fenyechaxun
 * @param currentpage
 * @return
 */
public List<Inquiryzb> findAll(Integer currentpage){
	List<Inquiryzb> list=this.xjdmapper.queryzb(currentpage);
	Inquiryzb inquiryzb=new Inquiryzb();
	for (Inquiryzb inquiryzbs : list) {
		inquiryzb.setInquiryxb(this.xjdmapper.queryxb(inquiryzbs.getBillNo()));
	}
	list.add(inquiryzb);
	/*for (Inquiryzb inq : list) {
		System.out.println("+++++++++++++++++++++++");
		System.out.println(inq);
	}*/
	return list;
}
/**
 * 主详新增
 * @param inquiryzb
 */
@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
public void insertinquizb(Inquiryzb inquiryzb){
	this.xjdmapper.insertinqui(inquiryzb);
	for (Inquiryxb inquiryxb : inquiryzb.getInquiryxb()) {
		inquiryxb.setBillNo(inquiryzb.getBillNo());
		this.xjdmapper.insertinquix(inquiryxb);
	}
}
/**
 * 根据日期生成单号
 * @param billDate
 * @return
 */
public String querybillno(String billDate){
	String billno=this.xjdmapper.querybillno(billDate);
	if(billno!=null||("").equals(billno)){
		billno=String.valueOf(Long.parseLong(billno)+1);
	}else{
		billno=billDate.replace("-","").toString()+"01";
	}
	return billno;
}
/**
 * zong
 * @return
 */
public int findCount(){
	return xjdmapper.queryCount();
	
}
/**
 * 删除
 * @param billNo
 */
public void deleteszx(String billNo){
	this.xjdmapper.deletexb(billNo);
	this.xjdmapper.deletezb(billNo);
	
}
/**
 * 删除状态
 * @param billNo
 */
public void detesta(String billNo){
	System.out.println("***********************************");
	this.xjdmapper.delestate(billNo);
}
/**
 * 修改
 * @param inquiryzb
 */
public void updates(Inquiryzb inquiryzb){
	this.xjdmapper.deletexb(inquiryzb.getBillNo());
	this.xjdmapper.deletezb(inquiryzb.getBillNo());
	this.xjdmapper.insertinqui(inquiryzb);
	System.out.println("添加从表==============");
	for (Inquiryxb inquiryxb : inquiryzb.getInquiryxb()) {
		inquiryxb.setBillNo(inquiryzb.getBillNo());
		this.xjdmapper.insertinquix(inquiryxb);
	}
}
/**
 * 审核
 * @param billNo
 * @return
 */
public void shstatus(String billNo){
	this.xjdmapper.shstatus(billNo);
}
/**
 * 反审核
 * @param billNo
 */
public void fanshenhe(String billNo){
	this.xjdmapper.fanshenhe(billNo);
}
/**
 * lishijiaoyichaxun
 * @param customerName
 * @return
 */
public List<history> queryhistory(String customerName){
	return this.xjdmapper.queryhistory(customerName);
}
}
